package com.project.andeper.paperproject;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class TypeActivity extends AppCompatActivity {

    DBManager dbManger;
    ListView lv;
    List<String> result = new ArrayList<>();
    String method ;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        method = getIntent().getStringExtra("method");
        dbManger = new DBManager(this);
        lv = new ListView(this);
        initData();
        if (result != null) {
            lv.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, result));
        }
        setContentView(lv);
        lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                Intent intent = new Intent(TypeActivity.this,ShowElectricActivity.class);
                intent.putExtra("method",method);
                intent.putExtra("value",result.get(i));
                startActivity(intent);
            }
        });
    }

    private void initData() {
        if (method.equals("search_by_eqnum")){
            result = dbManger.searchField("number");
            method = "number";
        }else if (method.equals("search_by_professioneq")){
            result = dbManger.searchField("machine");
            method = "machine";
        }else if (method.equals("search_by_type")){
            result = dbManger.searchField("variety");
            method = "variety";
        }else if (method.equals("search_by_userfor")){
            result = dbManger.searchField("department");
            method = "department";
        }else if (method.equals("search_by_department")){
            result = dbManger.searchField("userFor");
            method = "userFor";
        }else if (method.equals("search_by_usetype")){
            result = dbManger.searchField("useType");
            method = "useType";
        }
    }


}
